package com.koalac.ironman.util;

import android.view.MotionEvent;
import android.view.View;
/**
 * 双击事件的发生
 * @author ebirdfighter  2014年9月26日
 */
public class MyDoubleClickListener implements View.OnTouchListener{

	int count = 0;
	long firstClickTime;
	long secondClickTime;
	final long doubleClickSpace = 1000;//两次点击之后的最长间隔时间
	private EventCallBack callBack;
	
	public interface EventCallBack{
		public void onDoubleClick();
	}
	
	public MyDoubleClickListener(EventCallBack callBack){
		this.callBack = callBack;
	}
	
	@Override
	public boolean onTouch(View v, MotionEvent event) {
		if(MotionEvent.ACTION_DOWN == event.getAction()){
			count++;
			if(count == 1){
				firstClickTime = System.currentTimeMillis();
			}else if(count == 2){
				secondClickTime = System.currentTimeMillis();
				/**
				 * 双击事件
				 */
				if(Math.abs(secondClickTime - firstClickTime) < doubleClickSpace){
					callBack.onDoubleClick();
					/**
					 * 执行双击事件
					 */
				}
				count = 0;
				firstClickTime = 0;
				secondClickTime = 0;
			}
		}
		return false;
	}

}
